package com.hepinghospital.user.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.rest.business.RestProxy
import com.rest.response.DicResponse
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

class DailyRegisterViewModel : ViewModel() {

    val dataChanged = MutableLiveData<Int>()

    val myList = mutableListOf<DicResponse>()

    val myListRight = mutableListOf<DicResponse>()

    var isFirst = true


    fun setListCheck(list: MutableList<DicResponse>, position: Int) {
        for (item in list) {
            item.flag = false
        }
        if (list.isNotEmpty()) {
            list[position].flag = true
        }
    }


    fun getDepartmentList(level: String, parentId: String, name: String, list: MutableList<DicResponse>) =
        RestProxy.getInstance().getDepartment3List(level, parentId, name, object : Observer<List<DicResponse>> {

                override fun onComplete() {
                }

                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                }

                override fun onNext(t: List<DicResponse>) {
                    list.clear()
                    list.addAll(t)
                    dataChanged.value = dataChanged.value?.plus(1)
                    isFirst = false
                }
            })
}